package com.link2room.blaster.service.impl;

import com.link2room.blaster.service.IMsgTemplateService;
import com.link2room.common.dao.ICommonDao;
import com.link2room.common.exception.SysException;
import com.link2room.common.jpa.criteria.CriteriaUtil;
import com.link2room.blaster.entity.MsgTemplate;
import com.link2room.enums.exception.BlasterSysExceptionEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by LN on 2016/10/27.
 */
@Service("msgTemplateService")
public class MsgTemplateServiceImpl implements IMsgTemplateService {
    @Resource
    private ICommonDao commonDao;
    @Override
    public MsgTemplate findTemplate(String lhotelGorupCode, String lhotelCode, String channel, String templateCode) throws Exception {
        MsgTemplate s = new MsgTemplate();
        s.setLhotelGroupCode(lhotelGorupCode);
        s.setLhotelCode(lhotelCode);
        s.setChannel(channel);
        s.setCode(templateCode);
        MsgTemplate res =  commonDao.findOne(MsgTemplate.class, CriteriaUtil.getCriteriaAllEQ(s));
        if(res == null){
            throw new SysException(BlasterSysExceptionEnum.NO_TEMPLATE);
        }
        return res;
    }
}
